<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
	<style type="text/css">
		.active{
			background: orange;
		}
	</style>
</head>
<body>
<p class="active">段落1</p>
<p>段落2</p>
<p>段落3</p>
<script type="text/javascript">
	let p = document.querySelectorAll('p')
	for(let i = 0; i < p.length; i++){
		//给每一个p标签绑定点击时间
		p[i].addEventListener('click',function(){
			//每次加类名之前 先清除上一个active
			document.querySelector('.active').classList.remove('active')

			this.classList.add('active')
		})
	}
</script>
</body>
</html>